package edu.jxnu.zhangjinsong.unemploymenttracker.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Response {
    private int code;
    private String message;
    private Object data;

    public Response() {
    }

    public Response(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功响应
     */
    public static Response success(Object data) {
        return new Response(200, "success", data);
    }

    /**
     * 成功响应（无数据）
     */
    public static Response success() {
        return new Response(200, "success", null);
    }

    /**
     * 失败响应
     */
    public static Response error(int code, String message) {
        return new Response(code, message, null);
    }

    /**
     * 分页响应
     */
    public static Response page(Object data, long total, int page, int size, int totalPages) {
        Map<String, Object> pageData = new HashMap<>();
        pageData.put("list", data);
        pageData.put("total", total);
        pageData.put("page", page);
        pageData.put("size", size);
        pageData.put("totalPages", totalPages);
        return new Response(200, "success", pageData);
    }
}